package cn.itsource.controller.system;





import cn.itsource.service.system.IMenuService;
import cn.itsource.system.domain.Menu;
import cn.itsource.system.query.MenuQuery;
import cn.itsource.utils.JsonResult;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api
@RestController
@RequestMapping("/menu")
public class MenuController {
    @Autowired
    private IMenuService menuService;


    @GetMapping
    public List<Menu>  select(){
        return menuService.selectAll();
    }

    @PatchMapping
    public JsonResult deleteMore(@RequestBody Long[] ids){
        try {
            menuService.deleteMore(ids);
            return JsonResult.success("删除用户数据成功！");
        }catch (Exception e){
            e.printStackTrace();
            return JsonResult.error();
        }
    }


    @DeleteMapping("/{id}")
    public JsonResult delete(@PathVariable("id") Integer id){
        menuService.delete(id);
        return JsonResult.success("删除用户数据成功！");
    }

    @PutMapping
    public JsonResult update(@RequestBody Menu menu) {
        System.out.println(menu);
        menuService.update(menu);
        return JsonResult.success("修改用户数据成功！");
    }

    @PostMapping
    public PageInfo<Menu> queryPage(@RequestBody MenuQuery menuQuery){

        return menuService.queryMenu(menuQuery);
    }


    @GetMapping("/menuTree")
    public List<Menu> treeType() {
        return menuService.menuType();
    }














}


